import Taro, {Component} from '@tarojs/taro'
import {View,Picker,Text} from "@tarojs/components"
import { AtList, AtListItem,AtIcon  } from "taro-ui"
import './index.scss'
import {getHomework} from "./service";
import {getGlobalData} from "../../global.d";
import {getNotice} from "../classNotice/service";

export default class Index extends Component {
    constructor(props) {
        super(props);
        this.state = {
          current: 0,
          selector:['全部','进行中','已截止'],
          selectorChecked:'全部',
          sel1: 0,
          json: []
        }
    }
  componentWillMount(){
      setTimeout(()=>{
        const user =  getGlobalData('user')
        this.getjson(user.userLastTimeClass.classKey)
      },4000)


  }
  async getjson(classKey){
    await getHomework(classKey).then(res=>{
      this.setState({
        json: res.data
      })
    })
  }
  onChange = e => {
    this.setState({
      selectorChecked: this.state.selector[e.detail.value],
      sel1: e.detail.value
    })
  }
      submit(){
        getHomework(this,state.sel1)
      }


    render() {

        return (
            <View>
              <View className='selectorChecked'>
                <Picker mode='selector'
                        range={this.state.selector}
                        onChange={this.onChange}
                >
                  <View className='pickerItem'>
                    <AtIcon prefixClass='icon' value='guolv' size='25' color='#719BEA'></AtIcon>
                    <Text> {this.state.selectorChecked}</Text>
                    <View className='icon_2'>
                      <AtIcon   value='chevron-down' size='25' color='#CCCCCC'></AtIcon>
                    </View>

                  </View>
                </Picker>
              </View>
              <View>
                <AtList>
                  {
                    this.state.json.map((item,index)=>{
                      return (
                          <AtListItem
                            title={item.title}
                            note={item.content}
                            extraText='详细信息'
                            arrow='right'
                            iconInfo={{ size: 25, color: '#FF4949', value: 'folder', }}
                          />
                      )
                    })
                  }
                </AtList>
              </View>
            </View>
        )
    }

}
